package com.poposchool.project.mapper;

import com.poposchool.project.entity.Role;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author Wang Jie
 * @Date 2022/7/4 16:32
 * @Version 1.0
 */
public interface RoleMapper {
    @Select("select * from sys_role")
    List<Role> findAll();

    @Select("select * from sys_role where id = #{id}")
    Role getRoleById(Integer id);

    @Insert("insert into sys_role (name, description)\n" +
            "values (" +
            "        #{name}," +
            "      #{description})")
    void insertRole(Role role);

    void insertRoles(List<Role> roles);

    @Delete("delete from sys_role where id = #{id}")
    void deleteUser(Integer id);

    void updateRole(Role role);

    @Select("select count(*) from sys_role")
    Integer getAllNum();

    List<Role> getPageRoles(@Param("pageNum") Integer pageNum,
                            @Param("pageSize") Integer pageSize,
                            @Param("name") String name
    );

    void batchDeleteRoles(@Param("ids") List<Integer> ids);

    @Select("select * from sys_role where name = #{name}")
    Role getRoleByName(String name);

    @Select("select * from sys_role where flag = #{flag}")
    Role getRoleByFlag(String flag);
}
